<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page contentType="text/html" %>
<%@ page pageEncoding="UTF-8" %>
<%
    InitialContext context = new InitialContext();
    DataSource dataSource =
            (DataSource) context.lookup("jpa/DSTest2");

    java.sql.Connection conn = null;
    java.sql.Statement sqlStmt = null; //语句对象
    java.sql.ResultSet sqlRst = null; //结果集对象
    try {
        conn = dataSource.getConnection();

        sqlStmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY);

//执行Sql语句
        String sqlQuery = "select sno,sname,sex,birthday,nationlity,Native,political,district,student_sourse,enter_year,school_year,banji from Student";
        sqlRst = sqlStmt.executeQuery(sqlQuery);

        // 使用execute()方法的示例,返回true表示是查询，返回false表示是更新，如果事先不知道sql语句是查询还是更新，可以使用excute()方法
//  if(sqlStmt.execute(sqlQuery))
//    sqlRst=sqlStmt.getResultSet();

%>
<center>学生信息表</center>
<table border="1" width="100%" bordercolorlight="#CC99FF" cellpadding="2" bordercolordark="#FFFFFF" cellspacing="0">
    <tr>
        <td align="center">学号</td>
        <td align="center">姓名</td>
        <td align="center">性别</td>
        <td align="center">生日</td>
        <td align="center">民族</td>
        <td align="center">政治面貌</td>
        <td align="center">校区</td>
        <td align="center">生源</td>
        <td align="center">入学年份</td>
        <td align="center">年级</td>
        <td align="center">班级</td>
    </tr>
    <% while (sqlRst.next()) { //取得下一条记录 %>
    <tr><!--显示记录-->
        <td><%=sqlRst.getString("sno")%>
        </td>
        <td><%=sqlRst.getString("sname")%>
        </td>
        <td><%=sqlRst.getString("sex")%>
        </td>
        <td><%=sqlRst.getString("birthday")%>
        </td>
        <td><%=sqlRst.getString("nationlity")%>
        </td>
        <td><%=sqlRst.getString("Native")%>
        </td>
        <td><%=sqlRst.getString("political")%>
        </td>
        <td><%=sqlRst.getString("district")%>
        </td>
        <td><%=sqlRst.getString("student_sourse")%>
        </td>
        <td><%=sqlRst.getString("enter_year")%>
        </td>
        <td><%=sqlRst.getString("school_year")%>
        </td>
        <td><%=sqlRst.getString("banji")%>
        </td>
    </tr>
    <% } %>
</table>
<%
    } catch (java.sql.SQLException e) {
        out.println(e.toString());
    } finally {
        //关闭结果集对象
        if (sqlRst != null) sqlRst.close();
        //关闭语句对象
        if (sqlStmt != null) sqlStmt.close();
        //关闭数据库连接
        if (conn != null) conn.close();
    }
%>

